package cn.z2huo.leetcode.problem.NO_0053;

public class Main2 {
	public int maxSubArray(int[] nums) {
		int result = nums[0];
		int sum = 0;
		for (int i = 0; i < nums.length; i++) {
			if (sum > 0) {
				sum += nums[i];
			}else {
				sum = nums[i];
			}
			result = Math.max(result, sum);
		}
		return result;
	}
	
	public static void main(String[] args) {
		int[] array = {-2,1,-3,4,-1,2,1,-5,4};
//		int[] array = {-2,1};
		Main2 main = new Main2();
		System.out.println(main.maxSubArray(array));
	}
}
